package common;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;

public class EarthImage {
  private BufferedImage img;
  public int degreeSeparation;
  public int pixelsPerCellX; //number of pixels per latitudal division
  public int pixelsPerCellY; //number of pixels per longitudal division
  private int imgWidth; // in pixels
  private int imgHeight; // in pixels
  public int numCellsX;
  public int numCellsY;
  private int radius;
  
  public EarthImage() {
    try {
      URL imgURL = getClass().getResource("earth-white.jpg");
      img = ImageIO.read(imgURL);
    }
    catch (IOException e) {
      e.printStackTrace();
    }
    setGridSize(Constants.DEFAULT_GRID_SPACING);
  }
  
  public void setGridSize(int degreeSeparation) {
    this.degreeSeparation = degreeSeparation;
    
    numCellsX = 360 / degreeSeparation;      
    pixelsPerCellX = img.getWidth() / numCellsX;
    imgWidth = numCellsX * pixelsPerCellX;

    numCellsY = 180 / degreeSeparation;
    pixelsPerCellY = img.getHeight() / numCellsY;
    imgHeight = numCellsY * pixelsPerCellY;
    radius = imgHeight/2;     
  }
  
  public int getRadius() {
    return radius;
  }
  
  public BufferedImage getBufferedImage() {
    return img;
  }
  
  public int getWidth() {
    return imgWidth;
  }
  
  public int getHeight() {
    return imgHeight;
  }
}
